package com.ziyia.wim.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.google.android.material.tabs.TabItem;
import com.google.android.material.tabs.TabLayout;
import com.ziyia.wim.R;
import com.ziyia.wim.adapter.MyViewPagerAdapter;
import com.ziyia.wim.adapter.ViewPagerAdapter;
import com.ziyia.wim.fragment.ContactsFragment;
import com.ziyia.wim.fragment.IndexFragment;
import com.ziyia.wim.fragment.InfoFragment;
import com.ziyia.wim.util.HttpUtil;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class Index extends BaseActivity {

    private ViewPager viewPager;

    private TabLayout tabLayout;

    private List<Fragment> fragments = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 获取ViewPager控件
        viewPager = findViewById(R.id.viewPager);

        // 获取 TabLayout
        tabLayout = findViewById(R.id.tab);

        // ViewPager 与 TabLayout的关联
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

        // TabLayout 与 ViewPager的关联
        tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));

        String uid = getIntent().getStringExtra("id");
        String username = getIntent().getStringExtra("username");

        Bundle bundle = new Bundle();
        bundle.putString("uid", uid);
        bundle.putString("username", username);

        IndexFragment indexFragment = new IndexFragment();
        indexFragment.setArguments(bundle);
        fragments.add(indexFragment);
        fragments.add(new ContactsFragment());
        fragments.add(new InfoFragment());
        MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(adapter);
    }
}